/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package com.unwiredgrain.modeling.sscm.impl;

import com.unwiredgrain.modeling.sscm.CppTemplateInstantiation;
import com.unwiredgrain.modeling.sscm.Protocol;
import com.unwiredgrain.modeling.sscm.ProtocolTemplateInstantiation;
import com.unwiredgrain.modeling.sscm.SSCMPackage;
import com.unwiredgrain.modeling.sscm.TemplateArgument;
import com.unwiredgrain.modeling.sscm.TemplateInstantiation;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;

import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Protocol Template Instantiation</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link com.unwiredgrain.modeling.sscm.impl.ProtocolTemplateInstantiationImpl#getProtocol <em>Protocol</em>}</li>
 *   <li>{@link com.unwiredgrain.modeling.sscm.impl.ProtocolTemplateInstantiationImpl#getSubCppArguments <em>Sub Cpp Arguments</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class ProtocolTemplateInstantiationImpl extends TemplateInstantiationImpl implements ProtocolTemplateInstantiation {
	/**
	 * The cached value of the '{@link #getProtocol() <em>Protocol</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getProtocol()
	 * @generated
	 * @ordered
	 */
	protected Protocol protocol;

	/**
	 * The cached value of the '{@link #getSubCppArguments() <em>Sub Cpp Arguments</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getSubCppArguments()
	 * @generated
	 * @ordered
	 */
	protected EList<CppTemplateInstantiation> subCppArguments;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected ProtocolTemplateInstantiationImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return SSCMPackage.Literals.PROTOCOL_TEMPLATE_INSTANTIATION;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Protocol getProtocol() {
		if (protocol != null && protocol.eIsProxy()) {
			InternalEObject oldProtocol = (InternalEObject)protocol;
			protocol = (Protocol)eResolveProxy(oldProtocol);
			if (protocol != oldProtocol) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, SSCMPackage.PROTOCOL_TEMPLATE_INSTANTIATION__PROTOCOL, oldProtocol, protocol));
			}
		}
		return protocol;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Protocol basicGetProtocol() {
		return protocol;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setProtocol(Protocol newProtocol) {
		Protocol oldProtocol = protocol;
		protocol = newProtocol;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, SSCMPackage.PROTOCOL_TEMPLATE_INSTANTIATION__PROTOCOL, oldProtocol, protocol));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<CppTemplateInstantiation> getSubCppArguments() {
		if (subCppArguments == null) {
			subCppArguments = new EObjectContainmentEList<CppTemplateInstantiation>(CppTemplateInstantiation.class, this, SSCMPackage.PROTOCOL_TEMPLATE_INSTANTIATION__SUB_CPP_ARGUMENTS);
		}
		return subCppArguments;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case SSCMPackage.PROTOCOL_TEMPLATE_INSTANTIATION__SUB_CPP_ARGUMENTS:
				return ((InternalEList<?>)getSubCppArguments()).basicRemove(otherEnd, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case SSCMPackage.PROTOCOL_TEMPLATE_INSTANTIATION__PROTOCOL:
				if (resolve) return getProtocol();
				return basicGetProtocol();
			case SSCMPackage.PROTOCOL_TEMPLATE_INSTANTIATION__SUB_CPP_ARGUMENTS:
				return getSubCppArguments();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case SSCMPackage.PROTOCOL_TEMPLATE_INSTANTIATION__PROTOCOL:
				setProtocol((Protocol)newValue);
				return;
			case SSCMPackage.PROTOCOL_TEMPLATE_INSTANTIATION__SUB_CPP_ARGUMENTS:
				getSubCppArguments().clear();
				getSubCppArguments().addAll((Collection<? extends CppTemplateInstantiation>)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case SSCMPackage.PROTOCOL_TEMPLATE_INSTANTIATION__PROTOCOL:
				setProtocol((Protocol)null);
				return;
			case SSCMPackage.PROTOCOL_TEMPLATE_INSTANTIATION__SUB_CPP_ARGUMENTS:
				getSubCppArguments().clear();
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case SSCMPackage.PROTOCOL_TEMPLATE_INSTANTIATION__PROTOCOL:
				return protocol != null;
			case SSCMPackage.PROTOCOL_TEMPLATE_INSTANTIATION__SUB_CPP_ARGUMENTS:
				return subCppArguments != null && !subCppArguments.isEmpty();
		}
		return super.eIsSet(featureID);
	}

	
	/**
	 * 
	 */
	@Override
	public TemplateArgument basicGetArgument() {
		return protocol;
	}
	
	@Override
	public EList<? extends TemplateInstantiation> getSubArguments() {
//		return new EcoreEList.UnmodifiableEList<TemplateArgument>(this, 
//												 				  SSCMPackage.Literals.TEMPLATE_ARGUMENT__SUB_ARGUMENTS,
//												 				  getSubCppArguments().size(),
//												 				  getSubCppArguments().toArray());
		
		return getSubCppArguments();
	}
} //ProtocolTemplateInstantiationImpl
